package com.soulapp.ui.fragment

import android.os.Bundle
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
import com.soulapp.hook.R
import com.soulapp.hook.hooker.SoulMenuHook

class SettingsFragment : PreferenceFragmentCompat() {
    override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
        // 使用 XML 资源加载偏好设置界面
        setPreferencesFromResource(R.xml.settings_preferences, rootKey)
    }

    // 代码创建偏好设置项
    fun buildTheCode() {
        // 创建 PreferenceScreen
        val screen = preferenceManager.createPreferenceScreen(preferenceManager.context)
        // 创建分类
        val category = PreferenceCategory(screen.context).apply {
            title = "SoulHook"
        }
        screen.addPreference(category)
        val dataList = SoulMenuHook.buildData()
        dataList.forEach { item ->
            val switchPreference = SwitchPreferenceCompat(screen.context).apply {
                title = item.name
                summary = item.summary
                setDefaultValue(item.enabled)
            }
            category.addPreference(switchPreference)
        }

        // 设置为当前屏幕
        preferenceScreen = screen
    }

}